package com.zzty.zzlp.serviceimpl;

import com.zzty.zzlp.dao.UserDao;
import com.zzty.zzlp.entity.User;
import com.zzty.zzlp.entity.User_info;
import com.zzty.zzlp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    public Boolean addUserByMail(User user){
        if(userDao.addUserByMail(user) == 1 ){
            return true;
        }else{
            return false;
        }
    }

    public Boolean setState(Integer id){
        if(userDao.setState(id) == 1){
            return true;
        }else{
            return false;
        }
    }

    public User findUserByCode(String code){
        return userDao.findUserByCode(code);
    }

    @Override
    public Boolean searchRepeatedName(String name) {
        if(userDao.searchRepeatedName(name).size() != 0){
            return true;
        }else{
            return false;
        }
    }

    public Boolean delCode(Integer id){
        if(userDao.delCode(id) == 1){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean searchRepeatedEmail(String email) {
        if(userDao.searchRepeatedEmail(email).size() != 0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean searchRepeatedTel(String tel) {
        if(userDao.searchRepeatedTel(tel).size() != 0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean isRightUser(String accountNum, String password) {
        if(accountNum != null) {
            if (accountNum.contains("@")) {
                if (userDao.searchUserByEmailAndPwd(accountNum, password) != null) {
                    return true;
                } else {
                    return false;
                }
            } else {
                if (userDao.searchUserByTelAndPwd(accountNum, password) != null) {
                    return true;
                } else {
                    return false;
                }
            }
        }else{
            return false;
        }
    }

    @Override
    public User searchUserByAccNum(String accountNum, String password) {
        if(accountNum.contains("@")){
            return userDao.searchUserByEmailAndPwd(accountNum, password);
        }else{
            return userDao.searchUserByTelAndPwd(accountNum, password);
        }
    }

    public Boolean addUserByTel(User user){
        if(userDao.addUserByTel(user) == 1 ){
            return true;
        }else{
            return false;
        }
    }

    public Boolean emailPwdRepaire(User user){
        if(userDao.emailPwdRepaire(user) == 1){
            return true;
        }else{
            return false;
        }
    }

    public Boolean changePwdByMail(User user){
        if(userDao.changePwdByMail(user) == 1){
            return true;
        }else{
            return false;
        }
    }

    public Boolean changePwdByTel(User user){
        if(userDao.changePwdByTel(user) == 1){
            return true;
        }else{
            return false;
        }
    }

    public User searchUserByPwdRepaire(String pwdRepaire){
        return userDao.searchUserByPwdRepaire(pwdRepaire);
    }

    public Boolean delPwdRepaire(Integer id){
        if(userDao.delPwdRepaire(id) == 1){
            return true;
        }else{
            return false;
        }
    }

	public User getUserByName(String name) {
        return userDao.getUserByName(name);
    }

    public void addUserInfo(User_info user_info){
        userDao.addUserInfo(user_info);
    }

    public User selectUserById(Integer id) {
        return userDao.selectUserById(id);


    }
    public List<Integer> searchStuIdByClazzID(Integer classId) {
        return userDao.searchStuIdByclazzId(classId);
    }

    public void changPwdById(User user){
        userDao.changPwdById(user);
    }
}
